package com.nazca.tvremote.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public final class Settings {

	public static final String SETTINGS = "SETTINGS";
	public static final String DST_ADDRESS = "DST_ADDRESS";
	public static final String DST_PORT = "DST_PORT";
	public static final String TOUCHPAD_SENSITIVITY_OF_LEFT_RIGHT = "TOUCHPAD_SENSITIVITY_OF_LEFT_RIGHT";
	public static final String TOUCHPAD_SENSITIVITY_OF_UP_DOWN = "TOUCHPAD_SENSITIVITY_OF_UP_DOWN";
	public static final String GESTURE_REMOTE_SPEED = "GESTURE_REMOTE_SPEED";
	public static final String TV_REGION = "TV_REGION";
	
	private Context mContext;
	public String mDstAddress;
	public int mDstPort;
	public int mTouchpadSensitivityOfLeftRight;
	public int mTouchpadSensitivityOfUpDown;
	/**
	 * [key:value] [0:1/4] [1:1/2] [2:1] [3:1.5] [4:2] 
	 */
	public int mGestureRemoteSpeed;
	public int mTVRegion;
	
	public Settings(Context context){
		mContext = context;
	}
	
	public static Settings getSettings(Context context){
		Settings settings = new Settings(context);
		SharedPreferences preferences = context.getSharedPreferences(SETTINGS, Context.MODE_PRIVATE);
		settings.mDstAddress = preferences.getString(DST_ADDRESS, null);
		settings.mDstPort = preferences.getInt(DST_PORT, 0);
		settings.mTouchpadSensitivityOfLeftRight = preferences.getInt(TOUCHPAD_SENSITIVITY_OF_LEFT_RIGHT, 50);
		settings.mTouchpadSensitivityOfUpDown = preferences.getInt(TOUCHPAD_SENSITIVITY_OF_UP_DOWN, 50);
		settings.mGestureRemoteSpeed = preferences.getInt(GESTURE_REMOTE_SPEED, 2);
		settings.mTVRegion = preferences.getInt(TV_REGION, 50);
		return settings;
	}
	
	public void commit(){
		SharedPreferences preferences = mContext.getSharedPreferences(SETTINGS, Context.MODE_PRIVATE);
		Editor editor = preferences.edit();
		editor.putString(DST_ADDRESS, mDstAddress);
		editor.putInt(DST_PORT, mDstPort);
		editor.putInt(TOUCHPAD_SENSITIVITY_OF_LEFT_RIGHT, mTouchpadSensitivityOfLeftRight);
		editor.putInt(TOUCHPAD_SENSITIVITY_OF_UP_DOWN, mTouchpadSensitivityOfUpDown);
		editor.putInt(GESTURE_REMOTE_SPEED, mGestureRemoteSpeed);
		editor.putInt(TV_REGION, mTVRegion);
		editor.commit();
	}
}
